/**
 * 
 */
package com.dsteiner.xelavos.client;


import com.dsteiner.widgets.client.DateUtilImpl;
import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PrefilledDateBox;
import com.dsteiner.widgets.client.PrefilledRichTextArea;
import com.dsteiner.widgets.client.PrefilledTextArea;
import com.dsteiner.widgets.client.PrefilledTextBox;
import com.dsteiner.widgets.client.SuggestBoxWidget;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.widgets.client.model.SuggestBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.CreateLeisureController;
import com.dsteiner.xelavos.client.model.CreateObjectModel;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DatePicker;

public class CreateLeisureWidget extends LazyWidget {

	private final CreateLeisureController createLeisureController;
	private final CreateObjectModel createObjectModel;
	private final MainTabModel mainTabModel;

	public CreateLeisureWidget(CreateLeisureController createLeisureController, CreateObjectModel createObjectModel,
			MainTabModel mainTabModel) {
		this.createLeisureController = createLeisureController;
		this.createObjectModel = createObjectModel;
		this.mainTabModel = mainTabModel;
	}
	
	@Override
	public Widget createContentWidget() {
		FlowPanelExt flowPanel = new FlowPanelExt();
		SuggestBoxModel nameTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget nameTextBox = new SuggestBoxWidget(nameTextBoxModel, 
				new SelectedTabSuggestBoxDataProvider(mainTabModel));
		nameTextBoxModel.setDefaultText("<span class=\"main\">nombre</span> <span class=\"requiredField\">*</span> (ej Fiesta de verano)");
		SuggestBoxModel placeTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget placeTextBox = new SuggestBoxWidget(placeTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		placeTextBoxModel.setDefaultText("<span class=\"main\">lugar</span> <span class=\"requiredField\">*</span> (ej Parque Central Xela)");
		PrefilledTextBoxModel descriptionTextBoxModel = new PrefilledTextBoxModel();
		descriptionTextBoxModel.setDefaultText("<span class=\"main\">descripcion</span> <span class=\"requiredField\">*</span> (ej " +
				"hay un gran baile folclorico con trajes tipicos y venta de comida)");
		PrefilledRichTextArea descriptionTextBox = new PrefilledRichTextArea(descriptionTextBoxModel);
		PrefilledTextBoxModel eventDateTextBoxModel = new PrefilledTextBoxModel();
		eventDateTextBoxModel.setDefaultText("<span class=\"main\">fecha</span> (ej 24/12/2009)");
		DatePicker datePicker = new DatePicker();
		PrefilledDateBox eventDateTextBox = new PrefilledDateBox(eventDateTextBoxModel, datePicker, DateUtilImpl.formatterSpanish);
		PrefilledTextBoxModel eventDateUntilTextBoxModel = new PrefilledTextBoxModel();
		eventDateUntilTextBoxModel.setDefaultText("<span class=\"main\">fecha hasta</span> (ej 26/12/2009)");
		PrefilledDateBox eventDateUntilTextBox = new PrefilledDateBox(eventDateUntilTextBoxModel, new DatePicker(), DateUtilImpl.formatterSpanish);
		PrefilledTextBoxModel eventHourTextBoxModel = new PrefilledTextBoxModel();
		eventHourTextBoxModel.setDefaultText("<span class=\"main\">hora</span> (ej 19:30)");
		PrefilledTextBox eventHourTextBox = new PrefilledTextBox(eventHourTextBoxModel);
		PrefilledTextBoxModel contactTextBoxModel = new PrefilledTextBoxModel();
		contactTextBoxModel.setDefaultText("<span class=\"main\">contacto</span> (ej direccion y/o email y/o telefono)");
		PrefilledTextArea contactTextBox = new PrefilledTextArea(contactTextBoxModel);
		
		contactTextBoxModel.setMaxCount(Constants.MAX_COUNT_STRING);
		
		flowPanel.add((Widget)nameTextBox);
		flowPanel.add((Widget)placeTextBox);
		flowPanel.add((Widget)eventDateTextBox);
		flowPanel.add((Widget)eventDateUntilTextBox);
		flowPanel.add((Widget)eventHourTextBox);
		flowPanel.add((Widget)contactTextBox);
		flowPanel.add((Widget)descriptionTextBox);
		
		nameTextBox.setTabIndex(92);
		placeTextBox.setTabIndex(93);
		eventDateTextBox.setTabIndex(94);
		eventDateUntilTextBox.setTabIndex(95);
		eventHourTextBox.setTabIndex(96);
		contactTextBox.setTabIndex(97);
		descriptionTextBox.setTabIndex(98);
		
		nameTextBox.getElement().getStyle().setZIndex(10);
		placeTextBox.getElement().getStyle().setZIndex(9);
		eventDateTextBox.getElement().getStyle().setZIndex(8);
		eventDateUntilTextBox.getElement().getStyle().setZIndex(7);
		eventHourTextBox.getElement().getStyle().setZIndex(6);
		contactTextBox.getElement().getStyle().setZIndex(5);
		descriptionTextBox.getElement().getStyle().setZIndex(4);
		
		createLeisureController.registerJsUtil(JsUtil.getInstance());
		createLeisureController.registerPlaceTextBoxModel(placeTextBoxModel);
		createLeisureController.registerNameTextBoxModel(nameTextBoxModel);
		createLeisureController.registerDescriptionTextBoxModel(descriptionTextBoxModel);
		createLeisureController.registerEventDateTextBoxModel(eventDateTextBoxModel);
		createLeisureController.registerEventDateUntilTextBoxModel(eventDateUntilTextBoxModel);
		createLeisureController.registerContactTextBoxModel(contactTextBoxModel);
		createLeisureController.registerCreateObjectWidget(this);
		createLeisureController.registerEventHourTextBoxModel(eventHourTextBoxModel);
		createLeisureController.registerCreateObjectModel(createObjectModel);
		
		return flowPanel;
	}
}